import 'package:flutter/material.dart';

class MySwitcher extends StatefulWidget {
  final bool value;
  final void Function(bool)? onChanged;
  const MySwitcher({super.key, required this.value, this.onChanged});

  @override
  State<MySwitcher> createState() => _MySwitcherState();
}

class _MySwitcherState extends State<MySwitcher> {
  late bool _active = false;
  void _change(bool active) {
    if (widget.onChanged != null) {
      widget.onChanged!(active);
    }

    setState(() {
      _active = active;
    });
  }

  @override
  void initState() {
    super.initState();
    setState(() {
      _active = widget.value;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Switch(value: _active, onChanged: _change);
  }
}
